package cn.scw.common.utils.poi;

import com.lowagie.text.Font;
import com.lowagie.text.*;
import com.lowagie.text.rtf.RtfWriter2;

import java.awt.*;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * @description:
 * @author: lj
 * @create: 2020-07-06
 **/
public class WordUtil {
    public WordUtil() {

    }


    /**
     * @param args
     */

    public static void main(String[] args) {
        creatDoc("D:\\home\\scw_print\\uploadPath\\upload\\经验.doc", "百度经验\n多多浏览",20);
    }

    public static void creatDoc(String path, String text,int fontSize) {
        //设置纸张的大小
        Document document = new Document(PageSize.A4);
        try {
            //创建word文档
            RtfWriter2.getInstance(document, new FileOutputStream(path));
            //打开文档
            document.open();
            //创建段落
            Paragraph p = new Paragraph(text, new Font(Font.NORMAL, fontSize, Font.BOLD, new Color(0, 0, 0)));
            //设置段落为居中对齐
            p.setAlignment(Paragraph.ALIGN_CENTER);
            //写入段落
            document.add(p);
            //关流
            document.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
}
